using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace igp.net
{
    /// <summary>
    /// Represents the log window.
    /// </summary>
    public partial class FormLog : Form
    {
        private List<string> mainLog;

        /// <summary>
        /// Updates the list of presented events.
        /// </summary>
        /// <param name="log"></param>
        public void Update(List<string> log)
        {
            mainLog = log;
            listView1.Items.Clear();

            foreach (string logItem in log)
            {
                listView1.Items.Add(logItem);
                listView1.Items[listView1.Items.Count - 1].ToolTipText = logItem;
                listView1.Items[listView1.Items.Count - 1].ImageIndex = logItem.Contains("error: ") ? 1 : 0;
            }
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        public FormLog()
        {
            InitializeComponent();
            imageList1.Images.Add(Properties.Resources.information);
            imageList1.Images.Add(Properties.Resources.error);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            mainLog.Clear();
            Update(mainLog);
        }
    }
}